<template>
	<view style="">
		<!-- 帖子列表 -->
		<view style="display: flex;">
			<!-- 第一列 -->
			<view style="width: 50%;">
				<template v-for="(good, index) in posts">
					<view @click="toTieZiPage(index)" v-if="index%2 == 0" style="margin: 10px auto; width: 95%;">
						<!-- 图片 -->
						<view style="width: 100%; height: 200px; border-radius: 10px; overflow: hidden;">
							<view style="display: flex; justify-content: center; align-items: center;">
								<u--image :src="good.img" height="200px"></u--image>
							</view>
						</view>
						<!-- 标题 -->
						<view class="u-demo-block">
							<view class="u-demo-block__content">
								<u--text :lines="2" :text="good.text" size="14" bold></u--text>
							</view>
						</view>
						<!-- 日期 -->
						<view class="u-demo-block">
							<view class="u-demo-block__content">
								<text style="font-size: 12px;">发布时间：{{good.date}}</text>
							</view>
						</view>
					</view>
				</template>
			</view>

			<!-- 第二列 -->
			<view style="width: 50%;">
				<template v-for="(good, index) in posts">
					<view @click="toTieZiPage(index)" v-if="index%2 != 0" style="margin: 10px auto; width: 95%;">
						<!-- 图片 -->
						<view style="width: 100%; height: 200px; border-radius: 10px; overflow: hidden;">
							<view style="display: flex; justify-content: center; align-items: center;">
								<u--image :src="good.img" height="200px"></u--image>
							</view>
						</view>
						<!-- 标题 -->
						<view class="u-demo-block">
							<view class="u-demo-block__content">
								<u--text :lines="2" :text="good.text" size="14" bold></u--text>
							</view>
						</view>
						<!-- 日期 -->
						<view class="u-demo-block">
							<view class="u-demo-block__content">
								<text style="font-size: 12px;">发布时间：{{good.date}}</text>
							</view>
						</view>
					</view>
				</template>
			</view>

		</view>
		
		<view style="width: 100%; text-align: center; margin: 10px;">
			<text>没有更多了 ~ </text>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userId: '',
				posts: []
			}
		},
		props: [
			'getUserId',
		],
		methods: {
			toTieZiPage(index) {
				let that = this;
				// console.log(index)
				uni.navigateTo({
					url: '/pages/UserTieZiPage/TieZiPage/TieZiPage?postId=' + that.posts[index].id
				});
			},
			getPosts() {
				let that = this;
				uni.request({
					method: 'GET',
					url: getApp().globalData.url + '/post/getPosts?userId=' + this.userId,
					success(res) {
						let posts = res.data;
						for (let i = posts.length-1; i >= 0; i--) {
							that.posts.push(posts[i]);
						}
					}
				})
			}
		},
		mounted() {
			this.userId = this.$props.getUserId;
			
			this.getPosts();
		}
	}
</script>

<style>

</style>